package com.example.tsbs.controller;

import com.example.tsbs.config.Response;
import com.example.tsbs.config.Result;
import com.example.tsbs.entity.Task;
import com.example.tsbs.service.TaskService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags="计算信息")
@RestController
@RequestMapping("/api/task")
public class TaskController {

    @Autowired
    private TaskService taskService;

    @ApiOperation("计算表文件存储")
    @PostMapping("/getTaskStorage")
    public Result<?> getTaskStorage(@Parameter(description = "主键id")@RequestParam(value = "id") Integer id) {
        if(ObjectUtils.isEmpty(taskService.getById(id))){
            return Result.error("id不存在！");
        }
        String res = taskService.getStorage(id);
        return Result.info(res);
    }

    @ApiOperation("http调用测试")
    @GetMapping("/httpApi")
    public String http(@Parameter(description = "主键id")@RequestParam(value = "id") Integer id) {

        log.info("http调用测试");
        return "http调用测试成功";
    }

//    @ApiOperation("获取计算列表")
//    @GetMapping("/getTask")
//    public Response<PageInfo<Task>> getTask(@RequestParam(value = "pageNumber",required = false, defaultValue = "1") int pageNumber,
//                                            @RequestParam(value = "pageSize",required = false, defaultValue = "10") int pageSize,
//                                            @Parameter(description = "是否完成(0:未完成,1:已完成)")@RequestParam(required = false) Integer done,
//                                            @Parameter(description = "计算类型")@RequestParam(required = false) String taskType) {
//        PageInfo<Task> pageInfo = taskService.get(pageNumber, pageSize, done, taskType);
//        return Response.success("获取成功！", pageInfo);
//    }

//    @ApiOperation("新增计算")
//    @PostMapping("/addTask")
//    public Response<?> addTask(@Parameter(description = "计算名称")@RequestParam(value = "name",defaultValue = "") String name,
//                                @Parameter(description = "方案主键")@RequestParam(value = "schemeId",defaultValue = "") Integer schemeId) {
//        Task part = new Task();
//        int result = taskService.add(part);
//        if (result == -1) {
//            return Response.error("计算名已存在！");
//        }
//        log.info("新增计算"+", 数据："+ JSON.toJSONString(part));
//        systemLogService.addLog("新增计算");
//        return Response.success("添加成功！");
//    }
//
//    @ApiOperation("删除计算")
//    @PostMapping("/deleteTask")
//    public Response<?> deleteTask(@Parameter(description = "计算ID") @RequestParam Integer id) {
//        if(ObjectUtils.isEmpty(taskService.getById(id))) {
//            return Response.error("该计算ID不存在！");
//        }
//        log.info("删除计算");
//        systemLogService.addLog("删除计算");
//        return Response.success("删除成功！");
//    }
//
//    @ApiOperation("编辑计算")
//    @PostMapping("/updateTask")
//    public Response<?> updateTask(@RequestBody Task part) {
//        Integer id = part.getId();
//        int result = taskService.updating(part, id);
//        if (result == -1) {
//            return Response.error("计算名已存在！");
//        }
//        log.info("编辑计算"+", 数据："+JSON.toJSONString(part));
//        systemLogService.addLog("编辑计算");
//        return Response.success("更新成功！");
//    }
//
//    @ApiOperation("依据id获取计算")
//    @GetMapping("/getTaskById")
//    public Response<Task> getTaskById(@Parameter(description = "计算ID")@RequestParam(value = "id") Integer id) {
//        Task part = taskService.getById(id);
//        if(ObjectUtils.isEmpty(part)) {
//            return Response.error("此计算id不存在！");
//        }
//        return Response.success("获取成功！", part);
//    }

}
